﻿using System;
using Microsoft.Xna.Framework;
using WindowsGame.Common.Library;
using WindowsGame.Common.Static;
using WindowsGame.Common.TheGame;

namespace WindowsGame.Common
{
	public static class MyGame
	{
		public static void Construct(IGameManager manager)
		{
			Manager = manager;
		}

		public static void Initialize()
		{
			Manager.Logger.Initialize();
			Manager.ConfigManager.Initialize();

			Manager.ContentManager.Initialize();
			Manager.ContentManager.LoadContentSplash();

			Manager.InputManager.Initialize();
			Manager.ResolutionManager.Initialize();
			Manager.ScreenManager.Initialize();
			Manager.ThreadManager.Initialize();
		}

		public static void LoadContent()
		{
			Engine.Game.IsFixedTimeStep = Constants.IS_FIXED_TIME_STEP;
			Engine.Game.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / Constants.FRAMES_PER_SECOND);
			Engine.Game.IsMouseVisible = Constants.IS_MOUSE_VISIBLE;

			Manager.ResolutionManager.LoadContent(Constants.IS_FULL_SCREEN, Constants.SCREEN_WIDE, Constants.SCREEN_HIGH,
				Constants.USE_EXPOSED, Constants.EXPOSE_WIDE, Constants.EXPOSE_HIGH);
		}

		public static void LoadContentAsync()
		{
			// Initialize() methods.
			Manager.DeviceManager.Initialize();
			Manager.NumberManager.Initialize();
			Manager.TextManager.Initialize();
			Manager.TextManager.InitializeBuild();

			// LoadContent() methods.
			Manager.ConfigManager.LoadContent();
			Manager.ContentManager.LoadContent();
			Manager.BoardManager.LoadContent();
			Manager.ScreenManager.LoadContent();
			Manager.SpriteManager.LoadContent();
			GC.Collect();
		}

		public static void UnloadContent()
		{
			Engine.Game.Content.Unload();
		}

		public static void Update(GameTime gameTime)
		{
			Manager.InputManager.Update(gameTime);
			Manager.ScreenManager.Update(gameTime);
		}

		public static void Draw()
		{
			Manager.ScreenManager.Draw();
		}

		public static void OnActivated()
		{
			// OnActivated code goes here.
		}
		public static void OnDeactivated()
		{
			// OnDeactivated code goes here.
#if ANDROID
			Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
			System.Environment.Exit(0);
#endif
		}

		public static IGameManager Manager { get; private set; }
	}
}